import React from 'react';
import { fetchGradeAndType } from '../service';

const useGradeAndType = query => {
    const [outData, setOutData] = React.useState([]);
    const [loading, setLoading] = React.useState(true);

    const fetchData = async () => {
        setLoading(true);
        const { data = [], code } = (await fetchGradeAndType(query)) || {};

        if (code === 10000) {
            setOutData(data);
        }
        setLoading(false);
    };

    React.useEffect(() => {
        fetchData();
    }, [query]);

    return [loading, outData];
};

export default useGradeAndType;
